package com.zhz.mall.common.util;

/**
 * <p>
 *     no stack trace information
 *     无堆栈异常信息。
 *     在需要通过异常来中断程序或者是通过异常实现跳转的场景中：
 *           堆栈信息并不显得那么重要。当我们new任何一种异常时，都会去爬取堆栈信息。 这是一件非常损耗性能的事
 *           当异常不需要爬取堆栈信息时，在大量异常抛出的情况下。性能则有指数级的提升
 *     建议后续需要通过抛出异常实现中断或是流程跳转的场景中:
 *           自定义的异常继承 com.ygp.its.infrastructure.config.exception.NotStackTraceException 而非Exception
 *
 *
 *  测试程序：
 *
 *  public class TestException extends Exception{
 *
 *
 * @Override
 *     public Throwable fillInStackTrace() {
 *         return this;
 *     }
 * }
 *    public static void main(String[] args) {
 *         a();
 *         b();
 *     }
 *
 *     public static void a() {
 *         long start = System.currentTimeMillis();
 *         for (int i = 0; i < 1000000; i++) {
 *             new NullPointerException();
 *         }
 *         System.out.println("nullPointerException " + (System.currentTimeMillis() - start));
 *     }
 *
 *     public static void b() {
 *         long start = System.currentTimeMillis();
 *         for (int i = 0; i < 1000000; i++) {
 *             new TestException();
 *         }
 *         System.out.println("TestException " + (System.currentTimeMillis() - start));
 *     }
 * </p>
 * @author zhouhengzhe
 * @since jdk1.8
 */
public class NotStackTraceException extends Exception {

    private static final long serialVersionUID = 169227985859929027L;

    public NotStackTraceException() {
    }

    public NotStackTraceException(Object o) {
        super(o.toString());
    }

    public NotStackTraceException(String message) {
        super(message);
    }

    public NotStackTraceException(String message, Throwable cause) {
        super(message, cause);
    }

    public NotStackTraceException(Throwable cause) {
        super(cause);
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

   public static class NotStackTraceRuntimeException extends RuntimeException {

        private static final long serialVersionUID = 2033906272529339144L;

        public NotStackTraceRuntimeException() {
        }

        public NotStackTraceRuntimeException(String message) {
            super(message);
        }

        public NotStackTraceRuntimeException(String message, Throwable cause) {
            super(message, cause);
        }

        public NotStackTraceRuntimeException(Throwable cause) {
            super(cause);
        }

        @Override
        public Throwable fillInStackTrace() {
            return this;
        }
    }

}
